#include "dbquery.h"
#include <stdlib.h>
#include <stdio.h>

void html(void) {
    const char *html_top = "Content-Type: text/html\n\n\
              <html><head><meta content=\"text/html; charset=UTF-8\" />\
              <link rel=\"stylesheet\" type=\"text/css\" href=\"page.css\">\
              <title>/v/ - Xonotic</title>\
              <p class='hidden'>:-) / nice one<br></p>";
    const char *html_bot = "<br><br>\
              </body></html>";
    const char *html_mid = "<br>\
              <H2>hi / good luck and have fun.<br><br>Available Pages</H2>\
              <H3>Map Leaderboards</H3>\
              <p>cts?map=[map name]</p>\
              <H3>Player Ranks</H3>\
              <p>cts?player=[client id fingerprint]<br>\
              <hr>";
    const char *qstr = getenv("QUERY_STRING");
    printf("%s", html_top);
    if (qstr == NULL) {
        printf("%s", html_mid);
    }
    getquery(qstr);
    printf("%s", html_bot);
}

// use with template
void templated(void) {
    const char *qstr = getenv("QUERY_STRING");
    getquery(qstr);
    return;
}

int main(void) {
#ifdef STATICGEN
    templated();
#else
    html();
#endif
    return 0;
}
